#ifndef _UTIL_H
#define _UTIL_H

#include "fixed.h"
 
// clamp a number within a specified range
float clampf(float val, float min, float max);

int clamp(int val, int min, int max);

fixedp clampq(fixedp val, fixedp min, fixedp max);

// returns the mean value of an array
short mean(short *buf, int len);

fixedp qmean(fixedp *buf, int len);

// returns the maximum value in buffer, and the index i at
// which it is located
float maxf(const float *buf, int *i, int len);

/* 
 * Super simple DFT computation by direct evaluation.
 * Primary concern is code size, not performance because this
 * code will only be executed once during initialization.
 * Returns the magnitude of the DFT of x in out, which
 * should be allocated by the caller. Since it only operates
 * on real signals, it only bothers computing the first N/2
 * samples of the DFT, so out need only be of length N/2
 */
void mydft(const short *x, float *out, int N);

const char *int2str(int i);


#endif // _UTIL_H
